package com.boil.qz.safekavass.web.controller;

import com.boil.pojo.Page2Vo;
import com.boil.pojo.ResultVo;
import com.boil.qz.safekavass.pojo.ReportRedpackVo;
import com.boil.qz.safekavass.service.RedpackService;
import com.boil.qz.safekavass.web.request.param.ListReportRedpackParam;
import com.boil.util.Constants;
import com.boil.util.OkBaseController;
import com.boil.util.Page2;
import com.boil.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * Created by ChenYong on 2017-11-02.
 * <br>
 * 红包 Controller。
 */
@Controller
@RequestMapping("/web/redpack")
public class RedpackController extends OkBaseController {
    /**
     * 注入红包 Service
     */
    @Autowired
    private RedpackService redpackService;

    /**
     * 举报红包列表页面。
     *
     * @param model 模型
     * @return 举报红包列表页面
     */
    @RequestMapping(method = RequestMethod.GET, value = "/report/list.html")
    public String listHtml(Model model) {
        return "/redpack/report/list";
    }

    /**
     * 获取举报红包列表 json。
     *
     * @param model  模型
     * @param param  举报红包列表的请求参数
     * @param errors 请求参数的校验结果
     * @return 举报列表 json
     */
    @RequestMapping(method = RequestMethod.GET, value = "/report/list.json")
    @ResponseBody
    public ResultVo listJson(Model model, @Valid ListReportRedpackParam param, BindingResult errors) {
        // 结果 Vo
        ResultVo resultVo = new ResultVo();
        // 查询分页实例
        Page2<ReportRedpackVo> page2 = Utils.getPage2(request, param, Constants.ID_STR);
        page2.getParams().put("reportCreatePerson", param.getReportCreatePerson());
        page2.getParams().put("reportHandlePerson", param.getReportHandlePerson());
        page2.getParams().put("reportName", param.getReportName());
        page2.getParams().put("sendTimeStartDate", param.getSendTimeStartDate());
        page2.getParams().put("sendTimeEndDate", param.getSendTimeEndDate());
        page2.getParams().put("refundTimeStartDate", param.getRefundTimeStartDate());
        page2.getParams().put("refundTimeEndDate", param.getRefundTimeEndDate());
        page2.getParams().put("reportCreatePersonPhone", param.getReportCreatePersonPhone());
        page2.getParams().put("mchBillno", param.getMchBillno());
        page2.getParams().put("status", param.getStatus());

        // 分页查询
        redpackService.findInPage(page2);

        // 获取 DataTables 专用分页映射实例
        Page2Vo<ReportRedpackVo> page2Vo = Utils.getPage2Vo(param, page2);

        resultVo.setResult(page2Vo);

        return resultVo;
    }
}